package cn.com.wdjedu.androidapp.wjeduandroid.ui.videoshow.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.com.wdjedu.androidapp.wjeduandroid.R;
import cn.com.wdjedu.androidapp.wjeduandroid.mvp.MvpFragment;
import cn.com.wdjedu.androidapp.wjeduandroid.mvp.video.videoBean;
import cn.com.wdjedu.androidapp.wjeduandroid.mvp.video.videoPresenter;
import cn.com.wdjedu.androidapp.wjeduandroid.mvp.video.videoview;
import cn.com.wdjedu.androidapp.wjeduandroid.support.lib.view.MyGridView;
import cn.com.wdjedu.androidapp.wjeduandroid.ui.videoshow.VideoShowActivity;
import cn.com.wdjedu.androidapp.wjeduandroid.ui.videoshow.adpter.ChapterFragmentAdapter;

/**
 * 章节页面
 */
public class ChapterFragment extends MvpFragment<videoPresenter> implements videoview {
    @BindView(R.id.item_chapter_num)
    TextView itemChapterNum;
    @BindView(R.id.item_chapter_name)
    TextView itemChapterName;
    @BindView(R.id.item_mylistview)
    MyGridView itemMylistview;

    public List<videoBean> lists=new ArrayList<>();
    public List<videoBean.DataBean.ListsBean> ListsPast=new ArrayList<>();//把ListBean传递给VideoActivity

    private ChapterFragmentAdapter ChapterAdapter;
    @Override
    protected videoPresenter createPresenter() {
        return new videoPresenter(this);
    }

    @Override
    protected void lazyLoad() {

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        View view = inflater.inflate(R.layout.item_viewshow_chapter, null);
        ButterKnife.bind(this, view);
        mvpPresenter.attach(this);
        initData();
        return view;
    }

    public ChapterFragmentAdapter getChapterAdapter() {
        return ChapterAdapter;
    }

    private void initData() {
        //获取当前播放的视频ID
        VideoShowActivity ac = (VideoShowActivity)getActivity();
        mvpPresenter.queryVideoData(ac.getPlayId());

        ChapterAdapter=new ChapterFragmentAdapter(mContext, R.layout.item_viewshow_chapter, lists);
        itemMylistview.setAdapter(ChapterAdapter);
    }



    @Override
    public void queryNewVideoData(videoBean VideoBean) {
        lists.clear();
        lists.add(VideoBean);
        //lists.add((VideoBean.getData().getLists());
        //lists.add(VideoBean);
        ListsPast=VideoBean.getData().getLists();
        ChapterAdapter.notifyDataSetChanged();
       // Toast.makeText(getActivity(),"准备传递的listBean大小为："+ListsPast.size(),Toast.LENGTH_SHORT).show();
    }

    public List<videoBean.DataBean.ListsBean> getListsPast() {
        return ListsPast;
    }


    @Override
    public void showLoading() {
    }

    @Override
    public void hideLoading() {
    }

    @Override
    public void showError(String error) {
    }

//    @Override
//    public List<ChaterBean> getList() {
//        List<ChaterBean> lists=new ArrayList<>();
//        ChaterBean chaterBean=new ChaterBean();
//        chaterBean.setChater("第一章");
//        chaterBean.setChaterDetails("基本工具");
//        List<ChaterBean.SubChater> l=new ArrayList<>();
//        for (int i=0;i<8;i++){
//            ChaterBean.SubChater s=new ChaterBean.SubChater();
//            s.setChaterNumber("1-1");
//            s.setChaterNumberDeatils("Ps之窗口菜单");
//            s.setTime("11:45");
//            l.add(s);
//        }
//
//        chaterBean.setList(l);
//        lists.add(chaterBean);
//        return lists;
//    }
//
//
//    @Override
//    protected BaseAdapter buildListAdapter() {
//        lists=new ArrayList<>();
//        lists=getList();
//        listAdapter=new ChapterFragmentAdapter(getActivity(), R.layout.item_viewshow_chapter,lists);
//        getListView().setAdapter(listAdapter);
//        return listAdapter;
//    }
//
//    @Override
//    protected void listViewItemClick(AdapterView parent, View view, int position, long id) {
//
//    }
//
//    @Override
//    protected MainPresenter createPresenter() {
//        return null;
//    }
}
